package com.project.internship.controller.practice;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.internship.entity.Position;
import com.project.internship.entity.StudentPosition;
import com.project.internship.entity.resp.RespBean;
import com.project.internship.entity.resp.RespPageBean;
import com.project.internship.service.PositionService;
import com.project.internship.service.StudentPositionService;
import com.project.internship.vo.StudentPositionVO;
import javafx.geometry.Pos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/practice/position")
public class PracticePositionController {

    @Autowired
    StudentPositionService spService;
    @Autowired
    PositionService positionService;

    /**
     * 获得分配到的学生信息包含职位信息
     * @param current
     * @param size
     * @param keyword
     * @return
     */
    @GetMapping("/")
    public RespPageBean getStudentToPosition(@RequestParam(defaultValue = "1") Integer current,
                                               @RequestParam(defaultValue = "10") Integer size,
                                               String keyword){
        Page<StudentPositionVO> page = new Page<>(current,size);
        Long total = spService.getStudentToPosition(page,keyword).getTotal();
        List<StudentPositionVO> data =  spService.getStudentToPosition(page,keyword).getRecords();

        return new RespPageBean(total,data);
    }

    @GetMapping("/base_position")
    public List<Position> getTheBasePosition(){
        return positionService.getTheBasePosition();
    }

    @PostMapping("/")
    public RespBean addStudentPosition(@RequestBody StudentPosition studentPosition){
        if(spService.addStudentPosition(studentPosition) == 1) {
            return RespBean.ok("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    @PutMapping("/")
    public RespBean updateStudentPosition(@RequestBody StudentPosition studentPosition){
        if(spService.updateStudentPosition(studentPosition) == 1){
            return RespBean.ok("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    @PostMapping("/add/")
    public RespBean addPosition(@RequestBody Position position){
        if(positionService.addPosition(position) == 1) {
            return RespBean.ok("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    @DeleteMapping("/delete/")
    public RespBean deletePosition(@RequestBody Position position){
        if(positionService.deletePosition(position) == 1) {
            return RespBean.ok("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

}
